import logger from "@/components/log";
import BaseService from "./base-service";
import store from "@/store";
/**
 * 平台基础业务
 */
class CommonService extends BaseService {
    constructor() {
        super("common");
    }

    /**
     * 显示时间
     */
    ["show time"](options) {
        const date = new Date();
        // 年月日
        let result = `${date.getFullYear()}-${
            date.getMonth() + 1
        }-${date.getDate()}`;
        // 时分秒
        result += ` ${date.getHours()}:${date.getMinutes()}:${date.getSeconds()}`;
        if (options && options.withDate) {
            return this.success(this.COMMAND_TYPE_SEARCH, result);
        }
        logger.info("执行[show time]成功");
        return this.success(this.COMMAND_TYPE_SEARCH, result);
    }

    /**
     * 调试api, 更新setting某个key
     * @param {*} options {module, key, value}
     */
    ["update setting"](options) {
        const module = options.m || options.module;
        if (!module) {
            return this.fail("未指定模块, 如search, widget, background");
        }
        const key = options.k || options.key;
        if (!key) {
            return this.fail("未指定要更新的key");
        }
        const value = options.v || options.value;
        if (!value) {
            return this.fail(`未指定[${key}]对应的值`);
        }
        store.dispatch("setting/updateSetting", {
            module: module,
            key: key,
            value: value,
        });
        return this.success(this.COMMAND_TYPE_EXECUTE, "更新成功");
    }
}

export default new CommonService();
